#  Copyright (c) 1997-2011
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
#  http://www.polymake.de
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-----------------------------------------------------------------------------
#

application 'polytope';

# closure with respect to Gomory-Chvatal cuts
sub gc_closure {
  my ($p) = @_;
  my ($n,$d)=($p->N_VERTICES, $p->AMBIENT_DIM);
  my $hilbert_ineqs=new Set<Vector<Integer>>;
  for (my $i=0; $i<$n; ++$i) {
    my $hb=normal_cone($p,$i)->HILBERT_BASIS;
    for (my $k=0; $k<$hb->rows(); ++$k) {
      my $this_vector=$hb->row($k);
      my $obj=new Vector<Rational>(0 | -$this_vector);
      my $val=new Integer(floor($obj * $p->VERTICES->[$i]));
      $hilbert_ineqs+=new Vector<Integer>($val | $this_vector);
    }
  }
  return new Polytope<Rational>(INEQUALITIES=>new Matrix<Rational>($hilbert_ineqs));
}

# Local Variables:
# c-basic-offset:2
# mode: perl
# End:
